#include<bits/stdc++.h>//P17
using namespace std;
const int N=100100;
struct mystack{
    char a[N];
    int t=0;
    void push(char x){a[++t]=x;}
    char top(){return a[t];}
    void pop(){t--;}
    int empty(){return t==0?1:0;}
}st;
int main(){
    int n;scanf("%d",&n);getchar();
    while(n--){
        while(true){
            char ch=getchar();
            if(ch==' '||ch=='\n'||ch==EOF){
                while(!st.empty()){printf("%c",st.top());st.pop();}
                if(ch=='\n'||ch==EOF)break;
                printf(" ");
            }
            else st.push(ch);
        }
        printf("\n");
    }
    return 0;
}